#ifndef MAP_H_INCLUDED
#define MAP_H_INCLUDED

#include "SDL/SDL.h"
#include "SDL/SDL_image.h"

#include "helpers.h"
#include "Tile.h"
#include "TileSheet.h"
#include "Object.h"

class Map
    {
    private:
        std::string mapFileLocation;
        std::vector<Tile*> tiles;
        std::map< std::string, std::vector<Object*> > objectLayers;

        int width, height, friction;
        std::string theme;

        std::pair<int, int> startLoc;

        TileSheet *tileSheet;

        SDL_Rect getTileScreenCoord(Tile* tile, SDL_Rect* camera);
        void drawBackground(SDL_Rect* camera, SDL_Surface* screen);
        void blitTile(SDL_Surface* screen, SDL_Rect* camera, Tile* tile);
        bool finished;

    public:
        Map();
        ~Map();

        std::vector<Tile*> get_Tiles();
        std::vector<Tile*>* get_TilesPointer();

        Tile* get_Tile(int x, int y);
        Tile* get_Tilepx(int x, int y);
        int get_Width();
        int get_Height();
        int get_Widthpx();
        int get_Heightpx();
        std::string get_theme();
        int get_fric();
        std::pair<int, int> get_start();

        std::vector<Object*>* getObjects(std::string);

        void set_start(std::pair<int, int>);
        void set_theme(std::string th);
        void set_Width(int newWidth);
        void set_Height(int newHeight);
        void set_TileSheet(Artist* artist, std::string filename);

        void unstick_me(SDL_Rect*);

        void loadObjectImages(Artist& artist);

        void drawMap(SDL_Surface* screen, SDL_Rect* camera);

        void drawObjects(SDL_Rect* camera, SDL_Surface* screen, std::string layer = "background", bool lock_position = false);

        //void drawMapSlice(SDL_Surface* screen, SDL_Rect* camera, int topLayer, int bottomLayer = 0);

        //void drawBlocks(SDL_Surface* screen, SDL_Rect* camera);

        bool loadMap(std::string filepath);

        bool solid_collision(Direction direction, SDL_Rect rect);
        bool solid_collision(Direction direction, int x, int y, int w=32, int h=32);

        bool tile_test(int type, int tile_x, int tile_y, SDL_Rect rect);
        bool tile_test(int type, int tile_x, int tile_y, int x, int y, int w, int h);

        bool is_done(int x, int y);
        void empty();

        void finish_map();
};
#endif // MAP_H_INCLUDED
